<?php
function getSmallLink($longurl){
	$url = "http://api.bit.ly/shorten?version=2.0.1&longUrl=$longurl&login=" . $bitly_username ."&apiKey=" . $bitly_key . "&format=json&history=1";

	$s = curl_init();
	curl_setopt($s,CURLOPT_URL, $url);
	curl_setopt($s,CURLOPT_HEADER,false);
	curl_setopt($s,CURLOPT_RETURNTRANSFER,1);
	$result = curl_exec($s);
	curl_close( $s );

	$obj = json_decode($result, true);
	return $obj["results"]["$longurl"]["shortUrl"];
}
?>